package com.jm.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.PageContext;

import com.jm.utils.ObjectHelper;

/**
 * @author yanjie
 *
 * 2011/09/17 8:34:37 AM
 */
public class DefaultPageProxy {
	public static BaseMainPage GetPage(PageContext pageContext,String strDefault) throws Exception{
		return GetPage(pageContext,strDefault,true);
	}
	public static BaseMainPage GetPage(PageContext pageContext,String strDefault,boolean binit) throws Exception
	{
		if(pageContext.getRequest().getAttribute(BasePage.TAG_CURRENT_PAGE) != null){
			 return (BaseMainPage)pageContext.getRequest().getAttribute(BasePage.TAG_CURRENT_PAGE);
		}else{
			HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
			Object objPage = ObjectHelper.Create(strDefault);
			if(objPage == null)
			{
				return null;
			}
			
			BaseMainPage pageEx = (BaseMainPage)objPage;
			if(binit){
				if(request.getRequestURI().endsWith("backend.jsp")){
					pageEx.setBackEndMode(true);
					pageEx.InitBackEnd(pageContext);
				}else{
					pageEx.Init(pageContext);
				}
			}
			return pageEx;
		}
	}
}
